import 'package:flutter/material.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_member_full_info.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart';
import 'package:video_ducafecat_flutter_v3/common/index.dart';

/// 群系统消息
/// https://comm.qq.com/im/doc/flutter/zh/SDKAPI/Class/Group/V2TimGroupTipsElem.html#type
class MsgGroupTipsElemWidget extends StatelessWidget {
  const MsgGroupTipsElemWidget(
      {super.key, this.membersList, required this.message});

  final List<V2TimGroupMemberFullInfo?>? membersList;
  final V2TimMessage message;

  // 消息提示
  Widget _buildTip(String tip) {
    return TextWidget.body1(
      tip,
      color: AppColors.secondary.withOpacity(0.5),
      softWrap: true,
      maxLines: null,
      textAlign: TextAlign.center,
    ).paddingVertical(AppSpace.listRow).center();
  }

  // 主视图
  Widget _buildView() {
    // 成员列表
    String? userIDs = message.groupTipsElem?.memberList
        ?.map((e) => e?.nickName ?? "")
        .toList()
        .join(",");
    // 如果没有成员列表，则使用操作者的昵称
    if (userIDs?.isEmpty ?? true) {
      userIDs = message.groupTipsElem?.opMember.nickName ?? "";
    }
    // 提示文字
    String tip = getIMGroupTipsTypeString(
      IMGroupTipsType.values[message.groupTipsElem?.type ?? 0],
      members: userIDs,
    );
    return _buildTip(tip);
  }

  @override
  Widget build(BuildContext context) {
    return _buildView();
  }
}
